package com.driving.single.common.school.service.impl;

import com.driving.single.common.domain.TbSchoolPhoto;
import com.driving.single.common.entity.PageResult;
import com.driving.single.common.mapper.TbSchoolPhotoMapper;
import com.driving.single.common.school.service.CommonSchoolPhotoService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;

import java.util.List;

@Service
public class CommonSchoolPhotoServiceImpl implements CommonSchoolPhotoService {
    @Autowired
    private TbSchoolPhotoMapper tbSchoolPhotoMapper;

    /**
     * 实现根据驾校ID   分页查询驾校相册   接口
     * @param schoolId 驾校主键
     * @param photoType 相册图片类型,1:训练场地,2:训练车,3:周边环境
     * @param page      当前页
     * @param rows      页显示数
     */
    @Override
    public PageResult selectSchoolPhotoAlbumBySidWithPage(Long schoolId, Integer photoType, Integer page,
                                                          Integer rows) {
        PageHelper.startPage(page,rows);

        Example example = new Example(TbSchoolPhoto.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo("schoolId",schoolId);
        if(photoType != null){
            criteria.andEqualTo("photoType",photoType);
        }
        List<TbSchoolPhoto> list = this.tbSchoolPhotoMapper.selectByExample(example);

        PageInfo<TbSchoolPhoto> pageInfo = new PageInfo<>(list);

        PageResult pageResult = new PageResult();
        pageResult.setResult(list);
        pageResult.setPageIndex(page);
        pageResult.setTotalPage(pageInfo.getPages());
        pageResult.setTotalSize(pageInfo.getTotal());

        return pageResult;
    }
}
